package com.njtech.pet.service.impl;

import com.njtech.pet.dao.PetDao;
import com.njtech.pet.entity.Pet;
import com.njtech.pet.entity.User;
import com.njtech.pet.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author:gm
 * Date:2020-03-15 12:12
 * Description:<描述>
 */

@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class PetServiceImpl implements PetService {
    @Autowired
    @Resource(name="petDao")
    private PetDao petDao;

    /**
     * 增加一条宠物数据
     * @param pet
     * @return
     */
    @Override
    public int insertPet(Pet pet) {
        return petDao.insert(pet);
    }

    /**
     * 删除一条宠物，只要改state为无效
     * @param pet
     * @return
     */
    @Override
    public int deletePet(Pet pet) {
        return petDao.updateByPetId(pet);
    }


    /**
     * 修改宠物的多个属性值
     * @param pet
     * @return
     */
    @Override
    public int updatePetMessage(Pet pet) {
        return petDao.updateByPetId(pet);
    }

    /**
     * 查询一个用户的所有pet用于显示
     * @param user
     * @return
     */
    @Override
    public List<Pet> selectByUserId(User user) {
        return petDao.selectByUserId(user);
    }

    /**
     *
     * @param id
     * @return
     */
    @Override
    public Pet selectByPetId(Integer id) {
        return petDao.selectByPetId(id);
    }


}
